#ifndef INCOGNITO_INCOGNITOBLOCKINGCLIENT_HH
#define INCOGNITO_INCOGNITOBLOCKINGCLIENT_HH

#include "incognito.h"
#include "incognito_proto.h"
/**
 *Zamienia wywolania bazujace
 * na callback'ach na zwykle wywolania blokujace.
 */
class IncognitoBlockingClient:public virtual refcount {
	private:
		IncognitoBlockingClient() {};

	protected:
		chord_node cnode;

		// Block insert
		//	callback
		void insert_cb(ptr<incognito_store_arg> sa, clnt_stat err);
		//	succeed?
		bool write_ok;

		// Block fetch
		// callback
		void retrieve_cb(ptr<incognito_fetch_arg> arg, incognito_fetch_res *res, clnt_stat err);

//		void retrieve_cb(str *buf, dhash_stat stat, ptr<dhash_block> bl, vec<chordID> vc);
		//	succeed?
		bool read_ok;

		volatile bool cb_ok;
		void wait_for_cb();
	public:
		class IncognitoException {};
		class IncognitoInsertException: IncognitoException {};
		class IncognitoRetrieveException: IncognitoException {};

		
		// Constructor/destructor
		IncognitoBlockingClient(chord_node node_arg);
		~IncognitoBlockingClient() {}

		// Block insertion
		// 	Inserts block with key =  hash(data).
		bigint insert(str data) throw(IncognitoInsertException);
		//	Inserts block of data with a given key, sets the key type.
		bigint insert(bigint key, str data, bool key_is_hash=true) throw(IncognitoInsertException);

		// Block fetching
		str retrieve(bigint key, bool key_is_hash=true) throw(IncognitoRetrieveException);
		

};

#endif  /* INCOGNITO_INCOGNITOBLOCKINGCLIENT_HH */
